<template>
	<view class="normal-login-container">
		<view class="logo-content">
			<text class="title">请注册</text>
		</view>
		<view class="login-form-content">
			<view class="input-item flex align-center">
				<view class="iconfont icon-user icon"></view>
				<input v-model="registerInfo.userName" class="input" type="text" placeholder="请输入账号" maxlength="30" />
			</view>
			<view class="input-item flex align-center">
				<view class="iconfont icon-password icon"></view>
				<input v-model="registerInfo.password" type="password" class="input" placeholder="请输入密码"
					maxlength="20" />
			</view>

			<view class="register-content">
				<button @click="handleRegister" class="login-btn cu-btn block bg-blue lground">立即注册</button>
			</view>
		</view>
		<view class="xieyi text-center">
			<text class="text-grey1">注册即代表同意</text>
			<text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
			<text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
		</view>
	</view>
</template>

<script setup>
	import modal from '@/plugins/modal'
	import {
		register
	} from '@/api/login'
	import {
		ref
	} from "vue";
	import config from '@/config.js'
	import useUserStore from '@/store/modules/user'
	const registerInfo = ref({
		userName: "",
		password: ""
	});
	//注冊
	async function handleRegister() {
		register(registerInfo.value).then(res => {
			//交互反馈
			uni.showToast({
				title: '注册成功',
				duration: 2000
			});
			//注册成功后跳转到登陆页面
			uni.navigateTo({
				url: '/pages/login'
			})
		})
	};
	// 隐私协议
	function handlePrivacy() {
		let site = globalConfig.value.appInfo.agreements[0];
		uni.navigateTo({
			url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
		});
	};
	// // 用户协议
	function handleUserAgrement() {
		let site = globalConfig.value.appInfo.agreements[1]
		uni.navigateTo({
			url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
		});
	};
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.normal-login-container {
		width: 100%;

		.logo-content {
			width: 100%;
			font-size: 21px;
			text-align: center;
			padding-top: 15%;

			.title {
				margin-left: 10px;
			}
		}

		.login-form-content {
			text-align: center;
			margin: 20px auto;
			margin-top: 15%;
			width: 80%;

			.input-item {
				margin: 20px auto;
				background-color: #f5f6f7;
				height: 45px;
				border-radius: 20px;

				.icon {
					font-size: 38rpx;
					margin-left: 10px;
					color: #999;
				}

				.input {
					width: 100%;
					font-size: 14px;
					line-height: 20px;
					text-align: left;
					padding-left: 15px;
				}

			}

			.login-btn {
				margin-top: 40px;
				height: 45px;
			}

			.xieyi {
				color: #333;
				margin-top: 20px;
			}

			.login-code {
				height: 38px;
				float: right;

				.login-code-img {
					height: 38px;
					position: absolute;
					margin-left: 10px;
					width: 200rpx;
				}
			}

			.register-content {
				margin-top: 10rpx;
				text-align: right;
			}
		}

		.buttom {
			.loginType {
				display: flex;
				padding: 100rpx 200rpx 150rpx 200rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-warning;
				}
			}
		}
	}
</style>